﻿package app.view.components.guiDima.sky 
{
	import app.view.events.KeyboardEventD;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	
	/**
	 * Облако с сообщением
	 * @author Dmitryi_Koruagin, icq:585466579, dmitryikoruagin@mail.ru, skype: ok_ru1
	 */
	public class SkyMesageDBase extends Sprite
	{
		// app.view.components.guiDima.sky.SkyMesageDBase
		public var txt:TextField;
		public var closeSkyMessageBtn:Sprite;
		
		private var _currentValue:String = '';
		private var _test:TextField;
		
		public function SkyMesageDBase() 
		{
			init();
		}
		
		private function init():void
		{
			//txt.wordWrap = true;
			//txt.multiline = true;
			//txt.maxChars = 600;
			
			
			var form:TextFormat = new TextFormat();
			form.font = '_sans';
			form.align = TextFormatAlign.JUSTIFY;
			form.size = 25;
			form.leftMargin = 10;
			form.rightMargin = 10;
			
			
			_test = new TextField();
			_test.width = txt.width;
			_test.textColor = 0x333333;
			_test.height = txt.height;
			_test.wordWrap = true;
			_test.multiline = true;
			_test.maxChars = 500;
			_test.defaultTextFormat = form;
			_test.type = TextFieldType.DYNAMIC;
			_test.mouseEnabled = false;
			addChild(_test);
			
			_test.x = Math.round(txt.x);
			_test.y = Math.round(txt.y);
			
			closeSkyMessageBtn.buttonMode = closeSkyMessageBtn.useHandCursor = true;
			closeSkyMessageBtn.addEventListener(MouseEvent.CLICK, onClickClose);
		}
		
		public function destroy():void
		{
			closeSkyMessageBtn.removeEventListener(MouseEvent.CLICK, onClickClose);
		}
		
		public function get currentValue():String { return _currentValue; }
		
		public function set currentValue(value:String):void 
		{
			_currentValue = value;
			
			//txt.htmlText = _currentValue;
			
			_test.text = _currentValue;
		}
		
		private function onClickClose(e:MouseEvent):void 
		{
			var ev:KeyboardEventD = new KeyboardEventD(KeyboardEventD.ON_CLOSE_SKY_MESSAGE);
			dispatchEvent(ev);
		}
		
	}

}